package file_watcher

import (
	"fmt"
	"log"
	"os"
	"strings"
)

func ModifyHandler(event *Event){

	var err error

	path := event.Info.Path

	f,err := os.Open(path)
	if err != nil{
		log.Fatal(err)
	}
	defer func() {
		err = f.Close()
		if err != nil {
			log.Fatal(err)
		}
	}()
	fstat,_ := f.Stat()
    reSize := fstat.Size()
    if int(reSize) < event.Info.Offset{
       event.Info.Offset = int(reSize)
       return
	}

	var readContent = make([]byte,int(reSize) - event.Info.Offset - 1)
	_,err = f.ReadAt(readContent,int64(event.Info.Offset))
	if err != nil{
		log.Fatal(err)
	}
	event.Info.Offset += len(readContent)
	fmt.Println(event.Info.Path + event.Option + strings.Replace(string(readContent), "\n", "", -1))
}

func DeleteHandler(){
}
